#!/usr/bin/perl

use warnings;
use strict;

use LWP::Simple;
use XML::Simple;

print "Content-Type: text/html; charset=iso-8859-1\n\n";

my $primera = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">
  <html xmlns=\"http://www.w3.org/1999/xhtml\">
    <head>
      <meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\" />
      <title>AAP</title>
    </head>
    <body>
     <table border=\"1\">\n";

my $url = 'http://www.elpais.com/rss/feed.html?feedId=1022';
my $web = LWP::Simple::get($url) || die "No se puede descargar la web $url";

my $xml = XML::Simple::XMLin($web);
my $items = $xml->{channel}->{item};
my @items = @{$items};

my $segunda = "";

$segunda = join "", $segunda, "        <tr>\n";
$segunda = join "", $segunda, "          <td align=\"center\">T&Iacute;TULO</td>\n";
$segunda = join "", $segunda, "          <td align=\"center\">FECHA</td>\n";
$segunda = join "", $segunda, "        </tr>\n";

foreach my $item (@items) {
  $segunda = join "", $segunda, "        <tr>\n";
  $segunda = join "", $segunda, "          <td>$item->{title}</td>\n";
  $segunda = join "", $segunda, "          <td>$item->{pubDate}</td>\n";
  $segunda = join "", $segunda, "        </tr>\n";
}

my $tercera = "      </table> 
    </body>
  </html>\n";

print $primera.$segunda.$tercera;
